package com.sky.com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    //根据分类id统计关联的菜品数量
    @Select("select count(*) from dish where category_id =#{id}")
    Integer countByCid(Long id);


    /**
     * 插入菜品数据
     *
     * @param dish
     * **/
   @AutoFill("insert")
   void insert(Dish dish);

    //菜品分页查询
    List<DishVO> list(DishPageDTO dishPageDTO);


    // 根据id查询
    @Select("select * from dish where id = #{dishId}")
    Dish getById(Long dishId);

    // 删除菜品
    @Delete("delete from dish where id = #{dishId}")
    void deleteById(Long dishId);

    //设置自动更新时间以及修改人
    @AutoFill("update")
    void update(Dish dish);

    List<Dish> paramList(DishDTO dishDTO);


    Integer countByIdsAndStatus(Long[] ids, Integer status);

    @Select("select count(*) from dish where status = #{status} and id in (\n"+
    " select dish_id from setmeal_dish where setmeal_id = #{setmealId}")
    Long countBySiAndStatus(Long setmealId,int status);

   // 根据分类id统计菜品数量
    @Select("select count(*) from dish where category_id=#{categoryId}")
    Integer countByCategoryId(Long categoryId);

    // 条件查询菜品列表
    List<DishVO> getList(DishPageDTO dishPageDTO);

    // 根据菜品名称查询
    @Select("select * from dish where name=#{name}")
    Dish getByNmae(String name);


    // 修改菜品
    @AutoFill("update")
    void updateById(Dish dish);

    /*统计指定状态菜品数量*/
    @Select("select count(*) from dish where status  = #{status}")
    Integer countByStatus(Integer status);

    List<Dish> getByIds(Long[] ids);
}
